<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-form-item label="物件表" prop="wlGoodsId">
									<el-input v-model="form.wlGoodsId" placeholder="请输入物件表" clearable></el-input>
								</el-form-item>
								<el-form-item label="属于运单 已下单" prop="wlWaybillId">
									<el-input v-model="form.wlWaybillId" placeholder="请输入属于运单 已下单" clearable></el-input>
								</el-form-item>
								<el-form-item label="用户" prop="hyUserId">
									<el-input v-model="form.hyUserId" placeholder="请输入用户" clearable></el-input>
								</el-form-item>
								<el-form-item label="所在仓库" prop="wlWarehouseId">
									<el-input v-model="form.wlWarehouseId" placeholder="请输入所在仓库" clearable></el-input>
								</el-form-item>
								<el-form-item label="现在仓库分区id 0已出库" prop="wlWarehouseFqId">
									<el-input v-model="form.wlWarehouseFqId" placeholder="请输入现在仓库分区id 0已出库" clearable></el-input>
								</el-form-item>
								<el-form-item label="派送单id" prop="wlWaybillPsId">
									<el-input v-model="form.wlWaybillPsId" placeholder="请输入派送单id" clearable></el-input>
								</el-form-item>
								<el-form-item label="所在包装袋id" prop="wlPackingbagId">
									<el-input v-model="form.wlPackingbagId" placeholder="请输入所在包装袋id" clearable></el-input>
								</el-form-item>
								<el-form-item label="第三方快递单号" prop="cmCode">
									<el-input v-model="form.cmCode" placeholder="请输入第三方快递单号" clearable></el-input>
								</el-form-item>
								<el-form-item label="编码/条形码-内部条形码" prop="goodCode">
									<el-input v-model="form.goodCode" placeholder="请输入编码/条形码-内部条形码" clearable></el-input>
								</el-form-item>
								<el-form-item label="品名" prop="goodName">
									<el-input v-model="form.goodName" placeholder="请输入品名" clearable></el-input>
								</el-form-item>
								<el-form-item label="收货机器号" prop="machine">
									<el-input v-model="form.machine" placeholder="请输入收货机器号" clearable></el-input>
								</el-form-item>
								<el-form-item label="重量kg" prop="gkg">
									<el-input v-model="form.gkg" placeholder="请输入重量kg" clearable></el-input>
								</el-form-item>
								<el-form-item label="长cm" prop="gm3Chang">
									<el-input v-model="form.gm3Chang" placeholder="请输入长cm" clearable></el-input>
								</el-form-item>
								<el-form-item label="宽cm" prop="gm3Kuan">
									<el-input v-model="form.gm3Kuan" placeholder="请输入宽cm" clearable></el-input>
								</el-form-item>
								<el-form-item label="高cm" prop="gm3Gao">
									<el-input v-model="form.gm3Gao" placeholder="请输入高cm" clearable></el-input>
								</el-form-item>
								<el-form-item label="体积立方米" prop="gm3">
									<el-input v-model="form.gm3" placeholder="请输入体积立方米" clearable></el-input>
								</el-form-item>
								<el-form-item label="材重" prop="gcz">
									<el-input v-model="form.gcz" placeholder="请输入材重" clearable></el-input>
								</el-form-item>
								<el-form-item label="异常情况 0正常 1无主 2破损 3违禁 4遗失,参数编码YcState" prop="wstate">
									<el-input v-model="form.wstate" placeholder="请输入异常情况 0正常 1无主 2破损 3违禁 4遗失,参数编码YcState" clearable></el-input>
								</el-form-item>
								<el-form-item label="0待入库 1执行中 8已签收" prop="status">
									<el-input v-model="form.status" placeholder="请输入0待入库 1执行中 8已签收" clearable></el-input>
								</el-form-item>
								<el-form-item label="创建时间" prop="createTime">
									<el-input v-model="form.createTime" placeholder="请输入创建时间" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					wlGoodsId: "",
					wlWaybillId: "",
					hyUserId: "",
					wlWarehouseId: "",
					wlWarehouseFqId: "",
					wlWaybillPsId: "",
					wlPackingbagId: "",
					cmCode: "",
					goodCode: "",
					goodName: "",
					machine: "",
					gkg: "",
					gm3Chang: "",
					gm3Kuan: "",
					gm3Gao: "",
					gm3: "",
					gcz: "",
					wstate: "",
					status: "",
					createTime: "",
				},
				//验证规则
				rules: {
					userName: [
						{required: true, message: '请输入名称'}
					],
					userAge: [
						{pattern: /^[0-9]*$/, message: '年龄需为数字', trigger: 'blur'}
					],
					price: [
						{pattern: /^\d+(\.\d+)?$/, message: '价格需为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await this.$API.gjwl.wlGoods.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.wlGoodsId = data.wlGoodsId;
				this.form.wlWaybillId = data.wlWaybillId;
				this.form.hyUserId = data.hyUserId;
				this.form.wlWarehouseId = data.wlWarehouseId;
				this.form.wlWarehouseFqId = data.wlWarehouseFqId;
				this.form.wlWaybillPsId = data.wlWaybillPsId;
				this.form.wlPackingbagId = data.wlPackingbagId;
				this.form.cmCode = data.cmCode;
				this.form.goodCode = data.goodCode;
				this.form.goodName = data.goodName;
				this.form.machine = data.machine;
				this.form.gkg = data.gkg;
				this.form.gm3Chang = data.gm3Chang;
				this.form.gm3Kuan = data.gm3Kuan;
				this.form.gm3Gao = data.gm3Gao;
				this.form.gm3 = data.gm3;
				this.form.gcz = data.gcz;
				this.form.wstate = data.wstate;
				this.form.status = data.status;
				this.form.createTime = data.createTime;
			}
		}
	}
</script>
<style>
</style>
